package org.androidpn.adapter;

import java.util.List;

import org.androidpn.R;
import org.androidpn.model.CUserInfo;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RecommendGVAdapter extends BaseAdapter {
	private Context context;
	private List<CUserInfo> cUserInfos;
	private static String[] mColorsString = { "#FFF87311", "#FFF4A816", "#FF60BC12", "#FF0FC178", "#FF1974BB",
			"#FFA43C9A", "#FFD91B5B", "#FF565656" };

	public void setcUserInfos(List<CUserInfo> cUserInfos) {
		this.cUserInfos = cUserInfos;
	}

	public RecommendGVAdapter(Context context) {
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return cUserInfos.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return cUserInfos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHodler viewHodler;
		if (arg1 == null) {
			arg1 = View.inflate(context, R.layout.search_result_lv_item, null);
			viewHodler = new ViewHodler();
			viewHodler.tvName = (TextView) arg1.findViewById(R.id.tv_name);
			arg1.setTag(viewHodler);
		} else {
			viewHodler = (ViewHodler) arg1.getTag();
		}
		viewHodler.tvName.setBackgroundColor(Color.parseColor(mColorsString[position % 8]));
		viewHodler.tvName.setText(cUserInfos.get(position).getName());
		return arg1;
	}

	class ViewHodler {
		TextView tvName;
	}

}
